﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Markup;
using System.Windows.Data;

namespace Halfwit.Converters
{
    public class FontScaleConverter : MarkupExtension, IValueConverter
    {
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var scale = System.Convert.ToDouble(value);
            var fontSize = System.Convert.ToDouble(parameter);

            return fontSize * scale;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var scale = System.Convert.ToDouble(value);
            var fontSize = System.Convert.ToDouble(parameter);

            return fontSize / scale;
        }

        #endregion
    }
}
